package gwt.immunology.client.mvp;

import gwt.immunology.client.place.AddPatientPlace;
import gwt.immunology.client.place.AllPatientsPlace;
import gwt.immunology.client.place.UserPlace;
import gwt.immunology.client.place.SearchPatientsPlace;

import com.google.gwt.place.shared.Place;
import com.google.gwt.place.shared.PlaceHistoryMapper;

public class AppPlaceHistoryMapper implements PlaceHistoryMapper {

    private static final String ALL_PATIENTS = "all-patients";
    private static final String SEARCH_PATIENTS = "search-patients";
    private static final String ADD_PATIENT = "add-patient";
    private static final String REGISTER_USER = "register-user";

    @Override
    public Place getPlace(String token) {
        if (token.equals(ALL_PATIENTS)) {
            return new AllPatientsPlace();
        }

        if (token.equals(SEARCH_PATIENTS)) {
            return new SearchPatientsPlace();
        }

        if (token.equals(ADD_PATIENT)) {
            return new AddPatientPlace();
        }

        if (token.equals(REGISTER_USER)) {
            return new UserPlace();
        }

        return null;
    }

    @Override
    public String getToken(Place place) {
        if (place instanceof AllPatientsPlace) {
            return ALL_PATIENTS;
        }

        if (place instanceof SearchPatientsPlace) {
            return SEARCH_PATIENTS;
        }

        if (place instanceof AddPatientPlace) {
            return ADD_PATIENT;
        }

        if (place instanceof UserPlace) {
            return REGISTER_USER;
        }

        return null;
    }

}
